<template>
  <div class="container">
    <div>
      <div class="menu-navbar">
        <el-button size="small" type="" @click="cancelSubmit">取消</el-button>
        <el-button size="small" type="primary" @click="createSubmit('updatelist')">确 定</el-button>
        
      </div>
      <div>
        <el-form :model="updatelist" label-position="top" size="small" ref="updatelist" :rules="appendrules" label-width="110px">
          <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="系统建设单位" prop="developmentUnit">
                <el-input :disabled="true" v-model="updatelist.developmentUnitName" placeholder="系统建设单位"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2">
              
               <div class="select-container">
                   <el-button size="mini" type="text" @click="selectDeveUnit" style="margin-top: 40px;">选择</el-button>
                </div>
                
              
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统名称（中文）" prop="chName">
                <el-input v-model="updatelist.chName"  placeholder="系统中文名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统名称（英文）" prop="znName">
                <el-input v-model="updatelist.znName" placeholder="系统英文名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态" prop="status">    
                <el-select v-model="updatelist.status" clearable placeholder="系统状态" :disabled="false">
                  <el-option
                    v-for="item in typeOptions"
                      :key="item.type"
                      :label="item.value"
                      :value="item.type">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统建设时间" prop="constructTime" :show-overflow-tooltip='false'>
                  <el-date-picker type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" placeholder="系统建设时间" v-model="updatelist.constructTime" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统运维截止时间" prop="operEndTime" :show-overflow-tooltip='false'>
                  <el-date-picker type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" placeholder="系统运维截止时间" v-model="updatelist.operEndTime" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统承建单位" prop="constructionUnit">
                <el-input v-model="updatelist.constructionUnit" placeholder="系统承建单位"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统运维单位" prop="operUnit">
                <el-input v-model="updatelist.operUnit"  placeholder="系统运维单位"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统URL地址" prop="url">
                <el-input v-model="updatelist.url" placeholder="系统URL地址"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统IP地址" prop="ip">
                <el-input v-model="updatelist.ip"  placeholder="系统IP地址"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统负责人" prop="systemLeader">
                <el-input v-model="updatelist.systemLeader" placeholder="系统负责人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="负责人办公电话" prop="officePhone">
                <el-input v-model="updatelist.officePhone"  placeholder="负责人办公电话"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="负责人移动电话" prop="mobile">
                <el-input v-model="updatelist.mobile" placeholder="负责人移动电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统所属网络区域" prop="netArea">
                <el-select v-model="updatelist.netArea" clearable placeholder="系统所属网络区域" :disabled="false">
                  <el-option
                    v-for="item in netAreaOptions"
                      :key="item.type"
                      :label="item.value"
                      :value="item.type">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
         <el-dialog
      title="选择建设单位"
      :visible.sync="dialogVisible"
      top="5vh"
      width="70%">
      <el-row>
        <el-col :span="24">
          <el-tree ref='tree'
                   :data="treeData"
                   v-loading="loading"
                   style="height: 400px; overflow: scroll"
                   :props="defaultProps"
                   :expand-on-click-node='false'
                   @node-click="handleNodeClick"
                   node-key="id"
                   :highlight-current='true'
                   :default-expand-all='true'></el-tree>
        </el-col>
        
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
   import {
  
  treeByParentId,
  treeById
 
} from '@/api/bussSystemManage/orgTreeExt'
import {
  
  subSysUpdate
} from '@/api/bussSystemManage/subSystemMgr'
  export default {
    data() {
      return {
         dialogVisible: false,
         treeData: [],
         
         loading: false,
        defaultProps: {
          children: 'children',
          label: 'name'
         },
        updatelist: this.$route.params.list,
        appendrules: {
         developmentUnit: [
            { message: '系统建设单位不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 255, message: '长度在 1 到 255 个字符', trigger: 'blur' }
          ],
          chName: [
            { message: '系统中文名称不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          znName: [
            { message: '系统英文名称不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          status: [
            { message: '系统状态不能为空', required: true, trigger: 'blur' }
           
          ],
          constructTime: [
            { message: '系统建设时间不能为空', required: true, trigger: 'blur' }
          ],
          operEndTime: [
            { message: '系统运维截止时间不能为空', required: true, trigger: 'blur' }
          ],
          constructionUnit: [
            { message: '系统承建单位不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          operUnit: [
            { message: '系统运维单位不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          url: [
            { message: '系统URL地址不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 255, message: '长度在 1 到 255 个字符', trigger: 'blur' }
          ],
          ip: [
            { message: '系统IP地址不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
           systemLeader: [
            { message: '系统负责人不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
          officePhone: [
            { message: '办公电话不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
          mobile: [
            { message: '移动电话不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
          netArea: [
            { message: '所属网络区域不能为空', required: true, trigger: 'blur' }
          ]
        },
        
         typeOptions: [
          {
            type: '0',
            value: '有效'
          },
          {
            type: '1',
            value: '禁用'
          },
          {
            type: '2',
            value: '删除'
          }
        ],
        netAreaOptions: [
          {
            type: '0',
            value: '政务网'
          },
          {
            type: '1',
            value: '政务网1'
          },
          {
            type: '2',
            value: '政务网2'
          }
        ]
      }
      
    },
    // 画面刚进入method
  created() {
    // this.getUnitName()
    
  },
    methods: {
      updateData() {
        subSysUpdate(this.updatelist).then(res => {
          // his.fetchData()
          // this.$refs['updatelist'].resetFields()
          console.log(res)
        }).catch((err) => {
          console.log(err)
        })
      },
      createSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // console.log(this.updatelist)
            this.updateData()
            this.$router.push({
              name: 'subSys'
            })
            this.$message({
              type: 'success',
              message: '编辑成功!'
            })
          } else {
            this.$message({
              type: 'danger',
              message: '编辑失败!'
            })
            console.log('error submit!!')
            return false
          }
        })
      },
      
      
      cancelSubmit() {
        this.$router.push({
          name: 'subSys'
        })
      },
      selectDeveUnit(){
        this.dialogVisible = true
        treeByParentId({ parentId: "****",status: "0" }).then(response => {
        this.treeData = response.data.data
      })
      },
      handleNodeClick(data) {
      
     
      this.updatelist.developmentUnit = data.id
      this.updatelist.developmentUnitName = data.name
      this.dialogVisible = false
    //  alert(this.appendlist.developmentUnit)
      
    },
    /*
    getUnitName(){

      //alert(this.updatelist.developmentUnit)

      var unit=[]
      var cnt = 0
     

      var param = {
        condition: [{
          'property': 'id',
          'value': this.updatelist.developmentUnit,
          'type': 'EQ'
        }]
      }
      this.$store.dispatch('orgTreeSelect', param).then(res => {
        unit = res.data.records
        cnt = res.data.count
        if(cnt==0)this.unitName = ""
        else this.unitName = unit[0].name
        this.loading = false
      }).catch((err) => {
        console.log(err)
      }) 
     
    }*/
    }
  }
</script>
<style scoped>
  .menu-navbar{
    padding:0 0 20px;
    text-align: right;
  }
  .container{
    padding: 20px;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }
</style>
